Skip to content

Convert GeoPointMapActivity to Fragment#7253

Open
seadowg wants to merge 13 commits into
getodk:masterfrom
seadowg:geopoint-fragment
Open

Convert GeoPointMapActivity to Fragment#7253
seadowg wants to merge 13 commits into
getodk:masterfrom
seadowg:geopoint-fragment

Conversation

@seadowg

@seadowg seadowg commented Jun 10, 2026

Copy link
Copy Markdown
Member

Work towards #7118

Why is this the best possible solution? Were any other approaches considered?

We ideally want to be showing the geo point map UI within FormFillingActivity so that we don't have to deal with passing reference geometry between Activity objects. Like with geopoly questions, I've converted it to a DialogFragment.

How does this change affect users? Describe intentional changes to behavior and behavior that could have accidentally been affected by code changes. In other words, what are the regression risks?

This significantly restructures the way geopoint with maps/placement-maps works, so we'll want to test this feature thoroughly. No changes to how maps work has been made, so this only needs to be tested with one source/style.

Before submitting this PR, please make sure you have:

  • added or modified tests for any new or changed behavior
  • run ./gradlew connectedAndroidTest (or ./gradlew testLab) and confirmed all checks still pass
  • added a comment above any new strings describing it for translators
  • added any new strings with date formatting to DateFormatsTest
  • verified that any code or assets from external sources are properly credited in comments and/or in the about file.
  • verified that any new UI elements use theme colors. UI Components Style guidelines

@seadowg seadowg force-pushed the geopoint-fragment branch from 89e5e17 to eb1223a Compare June 10, 2026 13:33
@seadowg seadowg changed the title Convert GeoPoinMapActivity to Fragment Convert GeoPointMapActivity to Fragment Jun 10, 2026
@seadowg seadowg changed the title Convert GeoPointMapActivity to Fragment Convert GeoPointMapActivity to Fragment Jun 10, 2026
@dbemke

dbemke commented Jun 11, 2026

Copy link
Copy Markdown

Tested with success!

Verified on a device with Android 10

Verified cases:

  • geopoints with and without map appearance in all sources of maps
  • saving and removing points, discarding changes
  • saved geopoints in the form map
  • checking real location points
  • offline layers and map styles

@WKobus

WKobus commented Jun 11, 2026

Copy link
Copy Markdown

Tested with success

Verified on Android 16

@seadowg seadowg marked this pull request as ready for review June 12, 2026 09:21
@seadowg seadowg requested a review from grzesiek2010 June 12, 2026 09:21

object BundleExt {

inline fun <reified T : Parcelable> Bundle.getParcelableExtraCompat(name: String): T? {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The name getParcelableExtraCompat is a bit misleading here - Extra implies an Intent (as in getXxxExtra), but this operates on a Bundle, which has no extras. Suggest renaming to getParcelableCompat.

import android.os.Parcelable
import androidx.core.os.BundleCompat

object BundleExt {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrapping a single extension function in an object adds an extra layer without much benefit. A top-level extension function would be more idiomatic and just as easy to import.

import org.odk.collect.geo.items.MappableItem
import org.odk.collect.maps.MapPoint
import org.odk.collect.testshared.FakeScheduler
import org.odk.collect.testshared.getOrAwaitValue

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are many unused imports here. Why did all checks pass?

import org.odk.collect.android.widgets.interfaces.GeoDataRequester
import org.odk.collect.android.widgets.utilities.BindAttributes.ALLOW_MOCK_ACCURACY
import org.odk.collect.androidshared.ui.DialogFragmentUtils
import org.odk.collect.geo.Constants.EXTRA_DRAGGABLE_ONLY

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This const is unused now, and we can remove it.

placeMarkerButton!!.isEnabled = false

captureLocation = true
pointFromIntent = true

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't come from an intent anymore so we should update the naming here.

}

private fun cancel() {
getParentFragmentManager().setFragmentResult(REQUEST_GEOPOINT, Bundle.EMPTY)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use the property parentFragmentManager.setFragmentResult(REQUEST_GEOPOINT, Bundle.EMPTY).

setView(this, R.layout.geopoint_layout, false);
} catch (NoClassDefFoundError e) {
Timber.e(e, "Google maps not accessible due to: %s ", e.getMessage());
ToastUtils.showShortToast(org.odk.collect.strings.R.string.google_play_services_error_occured);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This disappeared. Don't we need it anymore?

import org.odk.collect.testshared.getOrAwaitValue

@RunWith(AndroidJUnit4::class)
class GeoPointMapDialogFragmentTest {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GeoPointMapDialogFragmentTest only covers the input configuration (configures GeoPointMapFragment with answer/draggable/readOnly), but none of the result-handling logic in onCreateFragment/onAnswer is tested. Compared to the sibling GeoPolyDialogFragmentTest there are some cases missing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants